import cn.fanqinghong.ymcc.UaaStart;
import cn.fanqinghong.ymcc.domain.Login;
import cn.fanqinghong.ymcc.domain.Permission;
import cn.fanqinghong.ymcc.mapper.PermissionMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.test.context.junit4.SpringRunner;
import sun.rmi.runtime.Log;

import java.util.List;
import java.util.stream.Collectors;

/**
 * FAN
 * 2022/8/11  16:16
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = UaaStart.class)
@Slf4j
public class atestste {
    @Autowired
    private PermissionMapper permissionMapper;
    @Test
    public void test(){
        Login login = new Login();
        List<Permission> permissions = permissionMapper.selectLoginPermission(1l);
        permissions.forEach(permission -> {
            System.out.println(permission.getSn());
        });
        List<SimpleGrantedAuthority> authorities = permissions.stream().map(permission -> {
            return  new SimpleGrantedAuthority(permission.getSn());
        }).collect(Collectors.toList());
        System.out.println(authorities);
        /*User user = new User(
                login.getUsername(),
                login.getPassword(),
                login.getEnabled(),
                login.getAccountNonExpired(),
                login.getCredentialsNonExpired(),
                login.getAccountNonLocked(),
                authorities
        );
     log.info(""+user);*/
    }
}
